<template>
	<view class="ui_nav" :style="'margin-top:'+top+'rpx;height:'+height+'rpx'">
		<u-icon name="arrow-left" size="20" @click="goBack" v-if="!isFirstPage"></u-icon>
		<u-icon name="home" size="24" @click="goBack" v-else></u-icon>
		<view class="ui_nav_title" :style="'line-height:'+ height+'rpx'">{{title}}</view>
	</view>
</template>

<script>
	export default {
		props: {
			title: {
				type: String,
				default: ''
			}
		},
		data() {
			return {
				top: 0,
				height: 88,
				isFirstPage: false,
			}
		},
		mounted() {
			let button = uni.getMenuButtonBoundingClientRect();
			console.log(button)
			this.top = button.top * 2;
			this.height = button.height * 2
			const pages = getCurrentPages()
			this.isFirstPage = pages.length === 1
		},
		methods: {
			goBack(){
				if(!this.isFirstPage){
					uni.navigateBack()
				}else {
					uni.switchTab({
						url: '/pages/index/index'
					})
				}
			}
		}
	}
</script>

<style lang="less">
	.ui_nav {
		width: 710rpx;
		display: flex;
		align-items: center;
		position: relative;
		z-index: 8888;
		&_title {
			position: absolute;
			width: 310rpx;
			left: 200rpx;
			top: 0rpx;
			text-align: center;
		}
	}
</style>